#!/usr/bin/env perl

use strict;
use lib qw(./lib ../lib);
use Test::More 'no_plan';
BEGIN { use_ok('GD::Barcode::DataMatrix::Engine') };
sub rs($$){ GD::Barcode::DataMatrix::Engine::CalcReed(@_); }
is_deeply rs([34,136,117],5),[34,136,117,131,9,70,176,138], '3/5';
is_deeply rs([34,136,256+117],5),[34,136,117,131,9,70,176,138], '3/5 bad';
is_deeply rs([202,251,226,117,201],7),[202,251,226,117,201,212,248,83,197,212,118,194], '5/7';
is_deeply rs([3,6,197,76,174,183,112,84],10),[3,6,197,76,174,183,112,84,79,132,127,218,196,33,142,180,199,23], '8/10';
is_deeply rs([51,135,245,108,104,192,137,46,16,32],11),[51,135,245,108,104,192,137,46,16,32,254,51,252,115,81,237,131,120,1,51,110], '10/11';
is_deeply rs([111,33,6,200,248,156,32,217,60,177,164,62],12),[111,33,6,200,248,156,32,217,60,177,164,62,161,135,196,58,103,221,94,118,48,228,142,206], '12/12';
is_deeply rs([214,182,84,185,147,18,163,109,123,179,114,215,39,97,196,125],14),[214,182,84,185,147,18,163,109,123,179,114,215,39,97,196,125,104,52,47,19,216,218,89,20,15,226,216,114,14,220], '16/14';
is_deeply rs([12,239,158,142,225,134,182,1,140,187,65,109,153,150,89,252,223,213],14),[12,239,158,142,225,134,182,1,140,187,65,109,153,150,89,252,223,213,112,141,135,73,179,56,251,224,249,129,255,207,182,56], '18/14';
is_deeply rs([178,175,105,225,15,128,252,89,34,46,108,87,95,149,222,221,69,114,41,58,243,5],18),[178,175,105,225,15,128,252,89,34,46,108,87,95,149,222,221,69,114,41,58,243,5,130,195,254,212,153,2,38,233,4,244,155,77,15,39,64,242,197,231], '22/18';
is_deeply rs([254,89,21,86,78,0,202,164,174,114,226,202,78,122,235,70,56,228,142,208,241,110,182,16,138,157,118,87,74,15],20),[254,89,21,86,78,0,202,164,174,114,226,202,78,122,235,70,56,228,142,208,241,110,182,16,138,157,118,87,74,15,140,220,61,141,144,83,24,10,82,170,86,62,60,27,146,77,100,135,61,100], '30/20';
is_deeply rs([25,234,36,69,12,183,81,232,108,44,249,41,154,194,252,33,15,203,119,98,234,244,240,28,194,182,11,115,235,27,158,252],24),[25,234,36,69,12,183,81,232,108,44,249,41,154,194,252,33,15,203,119,98,234,244,240,28,194,182,11,115,235,27,158,252,151,8,215,180,142,171,124,79,73,175,8,120,55,4,73,17,92,39,8,69,103,31,133,147], '32/24';
is_deeply rs([46,124,81,161,98,231,95,194,148,82,152,175,249,82,44,42,240,184,127,188,209,67,91,192,71,87,84,106,145,16,125,78,189,137,31,186],24),[46,124,81,161,98,231,95,194,148,82,152,175,249,82,44,42,240,184,127,188,209,67,91,192,71,87,84,106,145,16,125,78,189,137,31,186,139,230,31,247,232,226,125,225,42,199,167,199,109,131,11,67,218,69,90,129,165,2,198,178], '36/24';
is_deeply rs([215,123,98,198,165,218,171,114,127,110,70,233,35,65,72,38,203,129,145,206,128,45,186,141,13,101,164,122,148,156,176,33,165,166,24,6,219,75,226,142,202,242,18,152],28),[215,123,98,198,165,218,171,114,127,110,70,233,35,65,72,38,203,129,145,206,128,45,186,141,13,101,164,122,148,156,176,33,165,166,24,6,219,75,226,142,202,242,18,152,196,41,143,132,10,1,94,15,131,23,221,243,36,74,82,177,34,42,9,128,46,162,221,18,97,86,3,2], '44/28';
is_deeply rs([3,176,99,253,90,214,165,238,164,251,183,188,111,68,189,36,252,115,236,117,63,142,147,205,36,139,93,161,216,97,192,141,28,250,177,167,6,58,178,184,186,100,134,157,136,60,153,198,241],28),[3,176,99,253,90,214,165,238,164,251,183,188,111,68,189,36,252,115,236,117,63,142,147,205,36,139,93,161,216,97,192,141,28,250,177,167,6,58,178,184,186,100,134,157,136,60,153,198,241,78,77,102,187,150,172,150,58,122,252,26,15,99,181,231,71,194,174,140,236,113,37,102,214,43,76,86,41], '49/28';
is_deeply rs([207,61,115,79,233,2,205,142,0,168,244,19,15,239,120,194,229,199,227,244,120,179,110,64,222,35,29,100,104,147,132,185,24,66,176,132,149,63,137,207,143,94,129,211,97,23,238,97,66,153,26,135,97,116,66,48,236,39,20,104,210,167],36),[207,61,115,79,233,2,205,142,0,168,244,19,15,239,120,194,229,199,227,244,120,179,110,64,222,35,29,100,104,147,132,185,24,66,176,132,149,63,137,207,143,94,129,211,97,23,238,97,66,153,26,135,97,116,66,48,236,39,20,104,210,167,63,193,199,251,172,179,49,211,98,104,189,146,148,149,226,133,161,37,202,70,160,215,139,68,7,61,84,16,166,210,145,222,93,210,51,195], '62/36';
is_deeply rs([169,137,72,15,152,154,119,187,145,94,30,214,76,195,130,221,245,250,179,216,36,112,150,9,163,209,252,249,125,151,162,177,73,137,176,86,29,47,83,38,10,163,244,136,153,160,30,225,227,103,139,154,8,223,117,82,25,225,122,237,201,124,132,87,144,222,12,26,166,210,242,106,243,185,161,111,125,233,152,110,55,188,53,177,52,40],42),[169,137,72,15,152,154,119,187,145,94,30,214,76,195,130,221,245,250,179,216,36,112,150,9,163,209,252,249,125,151,162,177,73,137,176,86,29,47,83,38,10,163,244,136,153,160,30,225,227,103,139,154,8,223,117,82,25,225,122,237,201,124,132,87,144,222,12,26,166,210,242,106,243,185,161,111,125,233,152,110,55,188,53,177,52,40,124,132,16,41,95,228,20,145,51,1,245,124,248,180,167,61,252,249,94,222,45,199,76,153,250,209,234,250,52,252,100,146,253,180,162,58,212,191,170,141,36,135], '86/42';
is_deeply rs([166,16,34,149,146,168,201,55,209,37,60,32,97,92,182,234,56,124,192,74,189,39,67,243,76,151,210,115,175,77,178,109,206,3,155,236,40,119,175,48,1,81,186,194,58,68,196,205,138,105,183,249,44,16,44,214,66,76,30,187,156,76,206,214,219,150,57,215,122,247,176,239,206,182,112,253,168,69,214,168,44,64,149,235,75,28,12,209,245,205,150,142],36),[166,16,34,149,146,168,201,55,209,37,60,32,97,92,182,234,56,124,192,74,189,39,67,243,76,151,210,115,175,77,178,109,206,3,155,236,40,119,175,48,1,81,186,194,58,68,196,205,138,105,183,249,44,16,44,214,66,76,30,187,156,76,206,214,219,150,57,215,122,247,176,239,206,182,112,253,168,69,214,168,44,64,149,235,75,28,12,209,245,205,150,142,78,5,224,28,23,157,82,210,187,153,101,29,57,154,15,199,46,140,233,38,150,196,81,129,48,116,31,110,9,22,225,54,194,27,231,48], '92/36';
is_deeply rs([98,215,188,202,123,156,125,184,251,161,184,157,173,108,174,159,156,198,85,171,229,60,254,216,144,182,53,131,139,22,68,233,210,176,179,165,41,144,188,178,214,168,181,162,245,155,202,89,12,187,139,249,161,198,61,64,25,68,77,148,22,173,155,199,242,189,6,128,98,241,177,84,168,193,5,236,82,243,229,1,107,202,115,219,85,190,188,36,170,199,104,60,83,111,66,78,73,92,175,119,126,27],42),[98,215,188,202,123,156,125,184,251,161,184,157,173,108,174,159,156,198,85,171,229,60,254,216,144,182,53,131,139,22,68,233,210,176,179,165,41,144,188,178,214,168,181,162,245,155,202,89,12,187,139,249,161,198,61,64,25,68,77,148,22,173,155,199,242,189,6,128,98,241,177,84,168,193,5,236,82,243,229,1,107,202,115,219,85,190,188,36,170,199,104,60,83,111,66,78,73,92,175,119,126,27,48,54,192,29,174,121,107,61,127,62,66,91,79,73,100,66,49,4,81,244,175,231,230,221,174,124,210,28,226,200,248,46,222,64,242,4,177,216,229,28,88,206], '102/42';
is_deeply rs([12,17,234,66,116,95,239,88,214,72,249,95,41,182,224,143,215,230,166,29,13,50,110,176,67,170,65,229,217,243,157,55,149,24,141,25,84,226,246,50,192,99,90,72,163,82,61,151,111,176,108,83,134,131,64,98,41,39,29,245,223,126,71,185,88,244,67,44,53,154,179,239,211,46,253,69,31,212,151,85,194,245,175,168,22,198,151,150,128,249,251,238,73,148,26,227,82,142,251,137,170,191,17,57,178,60,226,30,196,16,199,232,26,139],48),[12,17,234,66,116,95,239,88,214,72,249,95,41,182,224,143,215,230,166,29,13,50,110,176,67,170,65,229,217,243,157,55,149,24,141,25,84,226,246,50,192,99,90,72,163,82,61,151,111,176,108,83,134,131,64,98,41,39,29,245,223,126,71,185,88,244,67,44,53,154,179,239,211,46,253,69,31,212,151,85,194,245,175,168,22,198,151,150,128,249,251,238,73,148,26,227,82,142,251,137,170,191,17,57,178,60,226,30,196,16,199,232,26,139,132,95,3,199,60,126,98,0,17,185,80,40,61,163,189,93,253,87,103,55,155,148,75,114,51,183,133,230,86,67,198,91,248,126,254,82,34,28,27,218,219,153,228,187,57,189,206,77], '114/48';
is_deeply rs([55,153,123,62,246,244,69,63,109,55,56,5,41,219,48,247,22,0,181,162,203,71,7,102,35,176,12,141,168,95,179,208,155,150,86,88,95,159,184,175,24,184,215,78,116,205,141,147,184,138,63,80,230,237,183,70,206,118,75,222,209,68,124,112,102,207,221,23,145,2,32,139,241,25,66,131,2,155,70,17,230,33,52,89,226,210,77,46,162,21,19,184,53,17,18,56,48,163,121,222,90,9,232,53,138,51,89,54,27,147,73,184,188,96,172,72,54,79,254,14,1,93,175,78,23,214,138,124,39,38,168,38,85,83,190,8],56),[55,153,123,62,246,244,69,63,109,55,56,5,41,219,48,247,22,0,181,162,203,71,7,102,35,176,12,141,168,95,179,208,155,150,86,88,95,159,184,175,24,184,215,78,116,205,141,147,184,138,63,80,230,237,183,70,206,118,75,222,209,68,124,112,102,207,221,23,145,2,32,139,241,25,66,131,2,155,70,17,230,33,52,89,226,210,77,46,162,21,19,184,53,17,18,56,48,163,121,222,90,9,232,53,138,51,89,54,27,147,73,184,188,96,172,72,54,79,254,14,1,93,175,78,23,214,138,124,39,38,168,38,85,83,190,8,22,147,226,72,164,114,51,64,48,140,218,215,237,7,251,222,202,245,174,119,233,105,55,253,3,22,16,71,11,255,173,139,179,166,223,153,33,62,110,203,6,94,227,91,238,180,105,32,198,98,183,176,38,104,203,105], '136/56';
is_deeply rs([221,69,37,230,38,190,121,148,100,145,189,44,132,126,230,209,203,81,113,111,239,191,139,158,133,69,201,141,187,192,0,221,69,106,27,121,167,52,19,231,55,144,85,217,26,253,222,185,128,161,37,245,164,220,36,29,133,14,56,217,168,250,34,206,240,191,235,43,220,250,30,123,145,7,185,70,37,212,139,24,48,44,77,232,169,189,240,188,53,138,69,88,105,98,127,163,113,212,67,145,126,249,103,70,211,148,25,140,50,11,5,23,195,242,140,243,129,86,14,73,197,190,134,31,72,236,7,121,215,210,5,31,33,115,132,226,32,63,183,16],56),[221,69,37,230,38,190,121,148,100,145,189,44,132,126,230,209,203,81,113,111,239,191,139,158,133,69,201,141,187,192,0,221,69,106,27,121,167,52,19,231,55,144,85,217,26,253,222,185,128,161,37,245,164,220,36,29,133,14,56,217,168,250,34,206,240,191,235,43,220,250,30,123,145,7,185,70,37,212,139,24,48,44,77,232,169,189,240,188,53,138,69,88,105,98,127,163,113,212,67,145,126,249,103,70,211,148,25,140,50,11,5,23,195,242,140,243,129,86,14,73,197,190,134,31,72,236,7,121,215,210,5,31,33,115,132,226,32,63,183,16,31,61,186,13,32,12,20,81,5,187,79,159,32,162,142,152,134,35,158,14,83,33,57,14,39,84,13,224,244,88,84,86,53,93,83,161,132,21,241,187,160,177,102,52,20,174,119,243,74,43,31,237,138,176,178,154], '140/56';
is_deeply rs([103,108,185,232,13,19,206,152,31,177,75,101,205,66,0,187,87,112,96,34,228,224,122,170,178,146,93,91,56,211,55,82,7,250,228,232,55,58,170,172,164,241,44,242,240,247,166,194,191,215,233,179,196,67,8,123,159,124,194,209,26,150,118,221,165,140,69,62,244,21,117,146,9,33,51,147,134,95,188,195,21,203,47,208,226,190,203,92,25,119,140,111,199,213,133,226,178,20,105,107,15,62,155,198,26,68,244,182,167,10,130,33,31,62,63,33,73,179,189,49,243,154,188,58,192,218,56,237,178,27,44,79,185,37,166,36,102,72,110,196,49,162,201,82],56),[103,108,185,232,13,19,206,152,31,177,75,101,205,66,0,187,87,112,96,34,228,224,122,170,178,146,93,91,56,211,55,82,7,250,228,232,55,58,170,172,164,241,44,242,240,247,166,194,191,215,233,179,196,67,8,123,159,124,194,209,26,150,118,221,165,140,69,62,244,21,117,146,9,33,51,147,134,95,188,195,21,203,47,208,226,190,203,92,25,119,140,111,199,213,133,226,178,20,105,107,15,62,155,198,26,68,244,182,167,10,130,33,31,62,63,33,73,179,189,49,243,154,188,58,192,218,56,237,178,27,44,79,185,37,166,36,102,72,110,196,49,162,201,82,242,77,142,5,20,94,72,83,150,122,22,139,245,216,61,231,109,227,222,32,144,243,153,190,56,252,124,93,215,223,56,55,45,135,76,53,16,160,142,254,24,151,26,36,49,118,18,117,198,200,124,241,252,250,3,250], '144/56';
is_deeply rs([174,109,109,129,18,116,201,146,176,138,53,48,168,181,209,78,196,227,226,38,71,121,132,113,121,52,46,212,55,29,214,6,238,206,252,110,111,91,93,242,37,198,107,64,171,101,71,154,228,192,160,245,153,142,133,184,15,41,192,133,106,122,33,170,185,98,51,23,184,34,244,190,62,250,171,149,1,220,151,216,108,12,58,243,246,60,141,219,142,176,227,94,232,176,108,217,106,254,84,178,22,237,25,12,106,236,102,183,49,106,198,212,90,87,93,96,164,188,9,243,127,216,11,75,12,42,188,48,177,0,12,129,52,153,94,71,37,99,253,2,125,243,229,14,216,70,97,80,213,9,16,246,74,156,159,173],62),[174,109,109,129,18,116,201,146,176,138,53,48,168,181,209,78,196,227,226,38,71,121,132,113,121,52,46,212,55,29,214,6,238,206,252,110,111,91,93,242,37,198,107,64,171,101,71,154,228,192,160,245,153,142,133,184,15,41,192,133,106,122,33,170,185,98,51,23,184,34,244,190,62,250,171,149,1,220,151,216,108,12,58,243,246,60,141,219,142,176,227,94,232,176,108,217,106,254,84,178,22,237,25,12,106,236,102,183,49,106,198,212,90,87,93,96,164,188,9,243,127,216,11,75,12,42,188,48,177,0,12,129,52,153,94,71,37,99,253,2,125,243,229,14,216,70,97,80,213,9,16,246,74,156,159,173,119,55,155,46,241,146,113,119,196,145,151,180,188,124,208,206,63,23,230,93,180,197,173,144,25,152,243,180,190,194,7,60,95,40,173,217,243,235,246,19,175,57,165,83,122,11,203,133,200,13,76,131,79,180,216,83,162,59,114,140,99,222], '156/62';
is_deeply rs([150,101,154,3,240,228,181,10,138,199,216,106,32,173,169,236,5,148,190,217,128,143,53,247,108,49,76,24,232,23,157,130,227,47,60,120,139,96,26,254,183,33,139,55,142,43,217,170,17,24,142,28,227,180,0,221,8,48,15,121,239,6,225,24,123,0,252,145,193,79,14,110,99,96,73,241,15,99,163,162,27,209,101,45,214,219,226,142,233,192,37,155,125,27,213,227,159,232,184,137,138,29,120,143,66,137,155,44,190,44,187,53,248,82,145,101,247,99,103,57,38,172,230,23,132,147,216,222,69,175,115,38,235,29,73,213,152,242,22,7,226,92,117,92,200,115,173,201,250,151,24,203,168,22,247,19,253,165,243,7,3,120,230],62),[150,101,154,3,240,228,181,10,138,199,216,106,32,173,169,236,5,148,190,217,128,143,53,247,108,49,76,24,232,23,157,130,227,47,60,120,139,96,26,254,183,33,139,55,142,43,217,170,17,24,142,28,227,180,0,221,8,48,15,121,239,6,225,24,123,0,252,145,193,79,14,110,99,96,73,241,15,99,163,162,27,209,101,45,214,219,226,142,233,192,37,155,125,27,213,227,159,232,184,137,138,29,120,143,66,137,155,44,190,44,187,53,248,82,145,101,247,99,103,57,38,172,230,23,132,147,216,222,69,175,115,38,235,29,73,213,152,242,22,7,226,92,117,92,200,115,173,201,250,151,24,203,168,22,247,19,253,165,243,7,3,120,230,55,125,52,56,143,73,237,124,156,117,236,118,41,177,225,17,37,53,152,89,146,108,21,160,209,248,222,155,43,19,17,201,166,47,33,27,181,220,5,19,235,227,67,118,83,48,97,82,72,216,92,120,224,179,57,16,0,153,118,41,22,182], '163/62';
is_deeply rs([101,89,69,211,178,219,117,170,133,187,141,79,157,253,76,199,95,52,26,192,252,138,69,72,7,122,53,90,101,106,148,94,22,140,219,17,139,222,109,115,96,239,98,129,215,42,120,22,161,231,116,209,209,53,106,202,70,141,85,48,54,89,235,112,207,97,150,82,101,15,232,118,215,36,232,29,90,244,67,211,162,212,91,124,17,219,229,101,190,163,26,27,161,183,130,23,213,59,155,207,202,68,157,226,24,41,120,48,219,193,43,173,76,131,29,227,48,192,133,155,150,182,51,25,131,39,157,145,88,92,249,175,91,160,23,69,148,81,172,113,189,134,66,73,71,214,184,6,53,209,64,109,242,93,218,39,211,38,5,177,160,202,10,235,156,5,159,53,245,102,221,250,48,89],68),[101,89,69,211,178,219,117,170,133,187,141,79,157,253,76,199,95,52,26,192,252,138,69,72,7,122,53,90,101,106,148,94,22,140,219,17,139,222,109,115,96,239,98,129,215,42,120,22,161,231,116,209,209,53,106,202,70,141,85,48,54,89,235,112,207,97,150,82,101,15,232,118,215,36,232,29,90,244,67,211,162,212,91,124,17,219,229,101,190,163,26,27,161,183,130,23,213,59,155,207,202,68,157,226,24,41,120,48,219,193,43,173,76,131,29,227,48,192,133,155,150,182,51,25,131,39,157,145,88,92,249,175,91,160,23,69,148,81,172,113,189,134,66,73,71,214,184,6,53,209,64,109,242,93,218,39,211,38,5,177,160,202,10,235,156,5,159,53,245,102,221,250,48,89,111,51,42,188,246,170,216,244,178,157,229,63,141,156,116,177,255,212,81,213,10,28,249,17,126,236,211,143,115,95,238,3,219,40,160,237,200,50,247,107,181,224,25,57,132,234,168,92,25,170,34,237,121,56,203,116,151,176,52,48,10,225,130,37,8,142,142,85], '174/68';
is_deeply rs([240,103,5,93,40,201,10,15,245,243,155,194,134,40,24,30,222,243,157,46,58,161,120,142,110,3,0,183,184,131,153,41,144,28,119,225,83,177,202,70,163,56,212,253,239,155,115,233,170,245,91,53,205,77,241,172,136,206,6,220,78,176,232,41,99,162,223,188,53,188,131,160,149,187,4,67,228,153,200,75,217,202,214,247,254,112,143,70,230,172,93,127,67,222,36,108,108,74,77,107,168,236,227,124,31,66,149,131,100,155,106,201,131,156,191,218,28,26,252,107,84,46,94,223,130,3,229,53,162,248,62,224,98,249,107,28,67,78,176,223,135,135,234,142,183,50,153,116,3,223,91,32,141,243,94,102,251,10,25,115,254,202,226,30,156,172,135,168,223,220,33,133,191,139,126],68),[240,103,5,93,40,201,10,15,245,243,155,194,134,40,24,30,222,243,157,46,58,161,120,142,110,3,0,183,184,131,153,41,144,28,119,225,83,177,202,70,163,56,212,253,239,155,115,233,170,245,91,53,205,77,241,172,136,206,6,220,78,176,232,41,99,162,223,188,53,188,131,160,149,187,4,67,228,153,200,75,217,202,214,247,254,112,143,70,230,172,93,127,67,222,36,108,108,74,77,107,168,236,227,124,31,66,149,131,100,155,106,201,131,156,191,218,28,26,252,107,84,46,94,223,130,3,229,53,162,248,62,224,98,249,107,28,67,78,176,223,135,135,234,142,183,50,153,116,3,223,91,32,141,243,94,102,251,10,25,115,254,202,226,30,156,172,135,168,223,220,33,133,191,139,126,66,54,15,188,198,198,158,85,248,249,191,58,103,79,95,198,155,107,166,20,37,93,225,136,203,220,101,206,251,36,68,52,247,82,224,110,60,181,27,119,14,30,146,136,25,145,184,152,162,132,97,143,82,147,17,224,218,219,71,247,240,206,244,255,162,224,92,102], '175/68';
